package br.gov.sjc.export;

import java.io.FileInputStream;
import java.io.IOException;
import java.net.SocketException;

import org.apache.commons.net.ftp.FTP;
import org.apache.commons.net.ftp.FTPClient;

public class FTPConnect  {
	 FTPClient ftp = new FTPClient();
	   public void main (String[] args) throws IOException {
		   
		   //ftp.connect( "www.sjc.sp.gov.br", 21 );
		   //ftp.login( "sjc_ftp", "7JWWqmQY" );
		   ftp.connect( "ftp.celebrandoavida.com", 21 );
		   ftp.login( "celebrandoavida", "c.c.b.r." );
		   
	   }

	 /**
	 * Faz o envio TXT do arquivo FTP.
	 * @param diretorio
	 * @param nomeArquivo
	 */
	   public void envioFTP(String diretorio, String nomeArquivo) {

			   try {
				   FileInputStream arqEnviar = new FileInputStream(diretorio+"/"+nomeArquivo);
				   ftp.setFileTransferMode(FTP.BINARY_FILE_TYPE);
				   ftp.setFileType(FTPClient.BINARY_FILE_TYPE);
				   ftp.storeFile(nomeArquivo, arqEnviar);
				   
			   } catch (SocketException e) {
				   e.printStackTrace();
			   } catch (IOException e) {
				   e.printStackTrace();
			   } catch (Exception e) {
				   e.printStackTrace();
			   }
	   }
	   public String Resposta(){
		   String Resp="";
		   String strResp;
		   
		   strResp = ftp.getReplyString();
		   
		   Resp = strResp;
		   
		   return Resp;
	   }
	   public void FechaConn(){
		   try {
			   ftp.logout();
			   ftp.disconnect();
		   } catch (SocketException e) {
			   e.printStackTrace();
		   } catch (IOException e) {
			   e.printStackTrace();
		   } catch (Exception e) {
			   e.printStackTrace();
		   }
	   }
}
